package com.zsrt.java.day20161227.lh.homework.demo04;

import java.util.Arrays;

import com.zsrt.java.day20161227.lh.homework.util.ArrayUtil;

/**
 * 
 * 已知：斗地主    54张牌     3*17  3张底牌  
 * 
 * 求：wanjia01  牌是什么
 * 	   wanjia02 	 
 * 	   wanjia03 
 * 		底牌            牌是什么
 * 
 * 思路：
 * 	1.牌一个数组 
 * 	2.三个玩家 用随机数发牌，组成三个新数组，遍历数组
 *	3.底牌   数组剩下的牌
 * @author My
 *
 */

public class DouDiZhu02 {
	
	
	public static void main(String[] args) {
		String[] pai=null;
		String[] xz={"黑","桃","梅","方"};
		String[] sz={"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
		String st="";
		
		String[] wanjia01=new String[17];
		String[] wanjia02=new String[17];
		String[] wanjia03=new String[17];
		
		StringBuffer sf=new StringBuffer();
		//生成牌
		for(int i=0;i<4;i++){
			String stb=xz[i];
			for(int j=0;j<13;j++){
				st=stb+sz[j]+",";
			    sf.append(st);
				
			}
		}
		sf.append("小鬼,大鬼");
		pai=sf.toString().split(",");
		
	//测试牌
		/*int counter=0;
		for (String s : pai) {
			counter++;
			System.out.println(s+counter);
		}*/
		
		//玩家1
		for(int i=0;i<17;i++){
			double ran=Math.random()*(54-i);
			int random=(int)Math.floor(ran);
//			System.out.println(random);
			wanjia01[i]=pai[random];
			pai=ArrayUtil.deleteArray(pai, pai[random]);
		}
		System.out.println("wanjia01的牌："+Arrays.toString(wanjia01));
		
		//玩家2
		for(int i=0;i<17;i++){
			double ran=Math.random()*(54-17-i);
			int random=(int)Math.floor(ran);
//			System.out.println(random);
			wanjia02[i]=pai[random];
			pai=ArrayUtil.deleteArray(pai, pai[random]);
		}
		System.out.println("wanjia01的牌："+Arrays.toString(wanjia02));
		//玩家3
		for(int i=0;i<17;i++){
			double ran=Math.random()*(54-34-i);
			int random=(int)Math.floor(ran);
//			System.out.println(random);
			wanjia03[i]=pai[random];
			pai=ArrayUtil.deleteArray(pai, pai[random]);
		}
		System.out.println("wanjia01的牌："+Arrays.toString(wanjia03));

		//底牌
		System.out.println("底牌："+Arrays.toString(pai));
		
		
	}
	
	
			
				
			
}
